#include "Layer.h"

double Layer::Eg() const {
    double temp;
    temp = alloy().firstCompound().Eg*x
           + alloy().secondCompound().Eg*(1.0-x)
           + alloy().Eg_bow*(x)*(1.0 - x);
    return temp;
}

double Layer::a_lc() const {
    double temp;
    temp = alloy().firstCompound().a_lc*x
           + alloy().secondCompound().a_lc*(1.0-x)
           + alloy().a_lc_bow*(x)*(1.0 - x);;
    return temp;

}

double Layer::delta_so() const {
    double temp;
    temp = alloy().firstCompound().delta_so*x
           + alloy().secondCompound().delta_so*(1.0-x)
           + alloy().delta_so_bow*x*(1.0 - x);;
    return temp;

}

double Layer::vbo() const {
    double temp;
    temp = alloy().firstCompound().vbo*x
           + alloy().secondCompound().vbo*(1.0-x)
           + alloy().vbo_bow*x*(1.0 - x);;
    return temp;

}

double Layer::mass_ef() const {
    double temp;
    temp = alloy().firstCompound().mass_ef*x
           + alloy().secondCompound().mass_ef*(1.0-x)
           + alloy().mass_ef_bow*x*(1.0 - x);;
    return temp;

}

double Layer::ac() const {
    double temp;
    temp = alloy().firstCompound().ac*x
           + alloy().secondCompound().ac*(1.0-x)
           + alloy().ac_bow*x*(1.0 - x);;
    return temp;
}

double Layer::av() const{
    double temp;
    temp = alloy().firstCompound().av*x
           + alloy().secondCompound().av*(1.0-x)
           + alloy().av_bow*x*(1.0 - x);;
    return temp;
}

double Layer::b() const {
    double temp;
    temp = alloy().firstCompound().b*x
           + alloy().secondCompound().b*(1.0-x)
           + alloy().b_bow*x*(1.0 - x);;
    return temp;
}

double Layer::c11() const{
    double temp;
    temp = alloy().firstCompound().c11*x
           + alloy().secondCompound().c11*(1.0-x)
           + alloy().c11_bow*x*(1.0 - x);;
    return temp;
}

double Layer::c12() const{
    double temp;
    temp = alloy().firstCompound().c12*x
           + alloy().secondCompound().c12*(1.0-x)
           + alloy().c12_bow*x*(1.0 - x);;
    return temp;
}

double Layer::cb(){
    if(a_base == 0.0)
        a_base = a_lc();
    double epsylon,deltaEhc;
    epsylon = (a_lc() - a_base)/a_base;
    deltaEhc = -2.0*ac()*(c11() - c12())*epsylon/c11();
    return vbo() + Eg() - deltaEhc;
}

double Layer::hh(){
    double epsylon, deltaEh,deltaEu;
    if(a_base == 0.0)
        a_base = a_lc();

    epsylon = (a_lc() - a_base)/a_base;
    deltaEh = 2.0*av()*(c11() - c12())*epsylon/c11();
    deltaEu = 2.0*b()*(c11() + 2.0*c12())*epsylon/c11();
    return vbo() + deltaEh - 0.5*deltaEu;
}
double Layer::lh(){
    if(a_base == 0.0)
        a_base = a_lc();
    double epsylon, deltaEh,deltaEu;
    epsylon = (a_lc() - a_base)/a_base;
    deltaEh = 2.0*av()*(c11() - c12())*epsylon/c11();
    deltaEu = 2.0*b()*(c11() + 2.0*c12())*epsylon/c11();
    return vbo() + deltaEh + 0.5*deltaEu - 0.5*deltaEu*deltaEu/delta_so();
}

